﻿CREATE PROCEDURE [dbo].[proc_Project_Task_Getlist_My]
	(
		@StartDate nvarchar(10),
		@EndDate nvarchar(10),
		@Stext nvarchar(50),
		@UserName nvarchar(50),
		@JD int,
		@StartIndex int,
		@EndIndex int
	)
AS
Begin
	Declare @sRq Datetime,@eRq Datetime
	Set @sRq = Convert(Datetime,@StartDate+' 00:00:00')
	Set @eRq = Convert(Datetime,@EndDate+' 23:59:59')

	;WITH list As(Select Top 3000 ROW_NUMBER() OVER (ORDER BY IsFinish,CreateDate Desc,Id Desc)AS Row
		,Id
		,TaskId
		,OrderId
		,ProjectId
		,CusName
		,Title
		,Description
,DownPerson
		,DownPersonName
		,ExecPersonName
		,StartDate
		,ISNULL(EndDate,'1900-01-01') As EndDate
		,datediff(day,StartDate,ISNULL(EndDate,GetDate())) As CountDay
		,IsFinish
		From Project_Task
		Where ExecPerson=@UserName And CreateDate>=@sRq And CreateDate<=@eRq
		And (@Stext='' Or CusName like '%'+@Stext+'%' Or Title like '%'+@Stext+'%')
		And (@JD=100 Or IsFinish=@JD)
	)

	Select *,(Select Count(0) From List) As RecordCount From list Where Row between @startIndex and @EndIndex Order By Row
End